package com.rush.manageepac.service.impl;

import com.rush.manageepac.dao.SettleDao;
import com.rush.manageepac.entity.Settle;
import com.rush.manageepac.service.intf.SettleService;
import com.rush.manageepac.util.StringUtil;
import com.rush.manageepac.vo.PageBean;
import com.rush.manageepac.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @outhor mjh
 * @date 2022/8/28
 */
@Service
public class SettleServiceImpl implements SettleService {
    @Autowired
    private SettleDao dao;
    @Override
    public R save(Settle settle) {
        if(dao.save(settle)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(Settle settle) {
        if(dao.update(settle)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R delete(int id) {
        if(dao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String name, int page, int limit) {
        if(StringUtil.isNotEmpty(name)){
            name="%"+name+"%";
        }
        int start=(page-1)*limit;

        return PageBean.ok(dao.selectCount(name),dao.selectPage(name,start,limit));
    }
}
